// 通过img和video的url组成的数组来删除服务器中的img,video
export function deleteUrls(arr_deleteUrl) {
  if (arr_deleteUrl.length == 0) {
    return
  }
  let arr_pathname = [];
  for (const item of arr_deleteUrl) {
    let {
      pathname
    } = new URL(item); //new URL()解决大图片加载失败问题。因为大图片的url中含有uploadid，导致url不能直接预览
    //decodeURIComponent函数解决中文乱码
    arr_pathname.push(decodeURIComponent(pathname));
  }
  if (arr_pathname.length !== 0) {
    return arr_pathname
  }
}

//获取img、video地址数组
export function get_urlImgVideo(elementId) {
  let arrImgVideo = document.getElementById(elementId).querySelectorAll("img,video");
  let arr = [];
  if (arrImgVideo.length !== 0) {
    arrImgVideo.forEach(item => {
      arr.push(decodeURIComponent(item.src));
    });
  }
  return arr;
}

// 两个数组取差集，返回arrA中有，而arrB中没有的。
// 如arrA = ["a", "b", "c", "d"];arrB = ["a", "b", "e"];则返回["c","d"]
export function arrayDifference(arrA, arrB) {
  return arrA.filter(item => !arrB.includes(item))
}